package com.yidu.qx.dao;

import com.yidu.qx.domain.QxCharacterEntity;
import com.yidu.qx.domain.QxRolesModulesEntity;
import com.yidu.qx.utils.Pages;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @program: jurisdiction
 * @description: 角色模块表实现类
 * @author: 张超
 * @create: 2019-09-25 14:03
 */
public class RolesModulesDaoImpl implements RolesModulesDao {
    private HibernateTemplate hibernateTemplate;

    public HibernateTemplate getHibernateTemplate() {
        return hibernateTemplate;
    }

    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
        this.hibernateTemplate = hibernateTemplate;
    }
    @Override
    public void add(QxRolesModulesEntity qxRolesModulesEntity) {
        hibernateTemplate.save(qxRolesModulesEntity);
    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void deleteAll(QxRolesModulesEntity qxRolesModulesEntity) {
        List list = hibernateTemplate.find("from QxRolesModulesEntity where chaId ='"+qxRolesModulesEntity.getRolId()+"'");
        if(list.size()>0){
            this.getHibernateTemplate().deleteAll(list);
        }
    }

    @Override
    public void update(QxRolesModulesEntity qxRolesModulesEntity) {

    }

    @Override
    public List<QxRolesModulesEntity> select(QxRolesModulesEntity qxRolesModulesEntity) {
        DetachedCriteria criteria = DetachedCriteria.forClass(QxRolesModulesEntity.class);

        if(!StringUtils.isEmpty(qxRolesModulesEntity.getChaId())){
            criteria.add(Restrictions.eq("chaId",qxRolesModulesEntity.getChaId()));
        }



        List<QxRolesModulesEntity> list  = (List<QxRolesModulesEntity>) hibernateTemplate.findByCriteria(criteria);
        return list;
    }

    @Override
    public List<QxRolesModulesEntity> findAll(QxRolesModulesEntity qxRolesModulesEntity, Pages pages) {
        return null;
    }

    @Override
    public QxRolesModulesEntity findById(Integer id) {
        return null;
    }

    @Override
    public Long count(QxRolesModulesEntity qxRolesModulesEntity) {
        return null;
    }
}